/**
 * 
 */
package com.calendar.guos.client.calendar;

import java.util.Date;

import com.google.gwt.gdata.client.DateTime;
import com.google.gwt.gdata.client.When;
import com.google.gwt.gdata.client.Where;
import com.google.gwt.gdata.client.atom.Text;
import com.google.gwt.gdata.client.calendar.CalendarEntry;
import com.google.gwt.gdata.client.calendar.CalendarEventEntry;
import com.google.gwt.gdata.client.calendar.ColorProperty;
import com.google.gwt.gdata.client.calendar.HiddenProperty;
import com.google.gwt.gdata.client.calendar.TimeZoneProperty;

/**
 * @author Amara Daal
 *
 */
public class Gfactory {


	  /**
	   * Create a new Calendar object
	   * @param newCalName
	   * @param newCalSummary
	   * @param newCalTimeZone
	   * @param newCalLocation
	   * @return the calendar object
	   */
	  public static CalendarEntry createCalendar( String newCalName, String newCalSummary, String newCalTimeZone, String newCalLocation, ColorProperty calColor) {
		//Create calendar
	    CalendarEntry entry = CalendarEntry.newInstance();
	    
	    //Create title of the calendar
	    entry.setTitle(Text.newInstance());
	    entry.getTitle().setText(newCalName);
	    
	    //Create calendar summary
	    entry.setSummary(Text.newInstance());
	    entry.getSummary().setText(
	        newCalSummary);
	    
	    //Set calendary time zone
	    entry.setTimeZone(TimeZoneProperty.newInstance());
	    entry.getTimeZone().setValue(newCalTimeZone);//"America/Los_Angeles"
	    
	    //Set the calendar location
	    Where where = Where.newInstance();
	    where.setLabel(newCalLocation);//"Mountain View, CA"
	    where.setValueString(newCalLocation);//"Mountain View, CA"
	    entry.addLocation(where);
	    
	    //Set Calendar properties
	    entry.setHidden(HiddenProperty.newInstance());
	    entry.getHidden().setValue(false);
	    entry.setColor(ColorProperty.newInstance());
	    entry.getColor().setValue(calColor.getValue());//ColorProperty.VALUE_RGB_2952A3
	    
	    
	    //showStatus("Creating calendar...", false);
	    
	    return entry;

	  }
	  
	  /**
	   * Create a calendar event by inserting an event entry into
	   * a calendar events feed.
	   * 
	   * @param eventsFeedUri The uri of the events feed into which to 
	   * insert the new event
	   */
	  @SuppressWarnings("deprecation")
	  public static CalendarEventEntry createEvent(String eventTitle, String eventDescription, String eventLocation, Date startTime, Date endTime) {

	    CalendarEventEntry entry = CalendarEventEntry.newInstance();
	    
	    //Construct and initialize entry title
	    entry.setTitle(Text.newInstance());
	    entry.getTitle().setText("GWT-Calendar-Client: "+eventTitle);
	    
	    //Construct and initialize entry description
	    entry.setContent(Text.newInstance());
	    entry.getContent().setText(eventDescription);
	    
	    //Construct and initialze  Time
	    When when = When.newInstance();
	    //endTime.setHours(endTime.getHours() + 1);
	    when.setStartTime(DateTime.newInstance(startTime));
	    when.setEndTime(DateTime.newInstance(endTime));
	    //Option to set the reminder
//	    Reminder reminder = Reminder.newInstance();
//	    reminder.setMinutes(30);
//	    reminder.setMethod(Reminder.METHOD_ALERT);
//	    when.addReminder(reminder);
	    entry.addTime(when);
	    return entry;

	    
	  }
}
